import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development env not use Lazy Loading,because Lazy Loading large page will cause webpack hot update too slow.so only in production use Lazy Loading

Vue.use(Router)

/* layout */
import Layout from '../views/layout/Layout'

/** note: submenu only apppear when children.length>=1
*   detail see  https://panjiachen.github.io/vue-element-admin-site/#/router-and-nav?id=sidebar
**/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if fasle ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  { path: '/authredirect', component: _import('login/authredirect'), hidden: true },
  { path: '/404', component: _import('errorPage/404'), hidden: true },
  { path: '/401', component: _import('errorPage/401'), hidden: true },
  // layout
  {
    path: '/schedule',
    component: Layout,
    redirect: 'noredirect',
    icon: 'table',
    noDropdown: true,
    children: [{
      path: 'index',
      component: _import('schedule/index'),
      name: '团课',
      meta: { title: 'schedule', icon: 'table', noCache: true }
    }]
  },
  {
    path: '/staff',
    component: Layout,
    redirect: 'staff/index',
    icon: 'people',
    children: [{
      path: 'index',
      component: _import('staff/index'),
      name: '员工',
      meta: { title: `staff`, icon: 'people', noCache: true }
    }]
  },
  {
    path: '/cardType',
    component: Layout,
    redirect: 'cardType/index',
    icon: 'documentation',
    children: [{
      path: 'index',
      component: _import('cardType/index'),
      name: '卡类',
      meta: { title: 'cardType', icon: 'documentation', noCache: true }
    }]
  },
  {
    path: '/giftCards',
    component: Layout,
    redirect: 'giftCards/index',
    icon: 'icon',
    children: [{
      path: 'index',
      component: _import('giftCards/index'),
      name: '赠卡',
      meta: { title: 'giftCards', icon: 'icon', noCache: true }
    }]
  },
  {
    path: '/classroom',
    component: Layout,
    redirect: 'classroom/index',
    icon: 'component',
    noDropdown: true,
    children: [{
      path: 'index',
      component: _import('classroom/index'),
      name: '课室',
      meta: { title: 'classroom', icon: 'component', noCache: true }
    }]
  },

  {
    path: '/course',
    component: Layout,
    redirect: 'course/index',
    icon: 'excel',
    noDropdown: true,
    children: [{
      path: 'index',
      component: _import('course/index'),
      name: '课程',
      meta: { title: 'course', icon: 'excel', noCache: true }
    }]
  }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  // edit
  {
    path: '/',
    component: Layout,
    redirect: '/classroom/edit',
    name: '课室操作',
    hidden: true,
    children: [{ path: 'classroom/edit', component: _import('classroom/edit') }]
  },
  {
    path: '/schedule',
    component: Layout,
    redirect: 'noredirect',
    name: '团课操作',
    hidden: true,
    children: [{ path: 'edit', component: _import('schedule/edit') }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/course/edit',
    name: '课程操作',
    hidden: true,
    children: [{ path: 'course/edit', component: _import('course/edit') }]
  },
  // other
  {
    path: '/error',
    component: Layout,
    redirect: 'noredirect',
    name: '错误页面',
    icon: '404',
    meta: {
      title: 'errorPages',
      icon: '404'
    },
    hidden: true,
    children: [
      { path: '401', component: _import('errorPage/401'), name: '401' },
      { path: '404', component: _import('errorPage/404'), name: '404' }
    ]
  },
  {
    path: '/error-log',
    component: Layout,
    redirect: 'noredirect',
    children: [{ path: 'log', component: _import('errorLog/index'), name: 'errorLog', meta: { title: 'errorLog', icon: 'bug' }}]
  },

  { path: '*', redirect: '/404', hidden: true }
]
